package com.qf.controller;

import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.service.GoodsService;
import com.qf.service.OrderService;
import com.qf.service.UserService;
import com.qf.util.ResponseUtil;
import com.qf.vo.DayStatis;
import com.qf.vo.GoodsStat;
import com.qf.vo.OrderStat;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/admin/stat")
public class StatController {
    @Autowired
    private UserService userService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private GoodsService goodsService;

    @RequiresPermissions("admin:stat:user")
    @RequiresPermissionsDesc(menu = {"统计","用户统计"},button = "查询")
    @GetMapping("/user")
    public Object user(){
        List columns=new ArrayList();
        columns.add("dayStr");
        columns.add("cnts");
        List<DayStatis> rows = userService.findDayStatis();
        Map map=new HashMap();
        map.put("columns",columns);
        map.put("rows",rows);
        return ResponseUtil.ok(map);
    }

    @RequiresPermissions("admin:stat:order")
    @RequiresPermissionsDesc(menu = {"统计","订单统计"},button = "查询")
    @GetMapping("/order")
    public Object order(){
        List columns=new ArrayList();
        columns.add("day");
        columns.add("orders");
        columns.add("customers");
        columns.add("amount");
        columns.add("pcr");
        List<OrderStat> rows = orderService.findOrderStat();
        Map map=new HashMap();
        map.put("columns",columns);
        map.put("rows",rows);
        return ResponseUtil.ok(map);
    }

    @RequiresPermissions("admin:stat:goods")
    @RequiresPermissionsDesc(menu = {"统计","商品统计"},button = "查询")
    @GetMapping("/goods")
    public Object goods(){
        List columns=new ArrayList();
        columns.add("day");
        columns.add("orders");
        columns.add("products");
        columns.add("amount");
        List<GoodsStat> rows = goodsService.findOrderStat();
        Map map=new HashMap();
        map.put("columns",columns);
        map.put("rows",rows);
        return ResponseUtil.ok(map);
    }


}
